-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
encoding/json: Add Custom JSON Package with Build Tag Support for Sonic #1623
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1623 +/- ##
=======================================
Coverage 37.07% 37.07%
=======================================
Files 414 414
Lines 180274 180274
=======================================
+ Hits 66835 66845 +10
- Misses 105574 105577 +3
+ Partials 7865 7852 -13
|
Flagged this as medium because this is beast. Sorry for those that cant use it. 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.github/workflows/tests.yml
Outdated
- os: windows-latest | ||
goarch: amd64 | ||
psql: true | ||
skip_wrapper_tests: true | ||
sonic: false | ||
- os: ubuntu-latest-sonic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should stick to the same style as the existing builds names with the false, false,false,true
, would also just be fine with including sonic
somewhere in the build name. Maybe its just not showing up below because its not merged?
Also, do we need two of each build? Would one extra one with sonic enabled suffice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should stick to the same style as the existing builds names with the false, false,false,true, would also just be fine with including sonic somewhere in the build name. Maybe its just not showing up below because its not merged?
That should have been reverted. I think.
Also, do we need two of each build? Would one extra one with sonic enabled suffice?
@thrasher- Confirming entire suite test or can just have one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can target amd64 linux for now since that's our main deployment OS in use ATM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -13,22 +13,52 @@ jobs: | |||
goarch: amd64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this line, would you consider a log on GCT start to say which one is enabled? Yes, you have build tags, but then it puts it in the logs of the application
Could add to the build tag files to call like json.Version()
where its fmt.Println("hello my name is Sonic and I gotta go fast, okay?")
as an example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comments feel very petty, but I'm happy overall with the work you've done
README.md
Outdated
@@ -77,6 +77,7 @@ However, we welcome pull requests for any exchange which does not match this cri | |||
+ WebGUI (discontinued). | |||
+ Exchange HTTP mock testing. See [mock](/exchanges/mock/README.md). | |||
+ Exchange multichain deposits and withdrawals for specific exchanges. See [multichain transfer support](/docs/MULTICHAIN_TRANSFER_SUPPORT.md). | |||
+ **Sonic JSON Integration**: Swap between the default Go 'encoding/json' package and the sonic library using go build tags for optimized JSON handling `-tags=sonic` or by using the make file `make sonic` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep styling in line with the others (or update the others) and update the template as well.
encoding/json/json.go
Outdated
|
||
package json | ||
|
||
import "encoding/json" //nolint:depguard // This is a wrapper package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update comment. This PR has no readme of new functionality being introduced. Explaining that its here for the rest of the application to use the default go json package would be nice
edit: finding it hard to use my own words. But saying that its the default json package used for GCT and that all uses of json should refer to this package would be good
encoding/json/common.go
Outdated
@@ -0,0 +1,13 @@ | |||
package json | |||
|
|||
import "encoding/json" //nolint:depguard // This is a wrapper package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update comment, but less detail needed than the other one
encoding/json/sonic.go
Outdated
func init() { | ||
log.Printf("Using %s for JSON encoding\n", Version) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes more sense to have this in common.go
because it doesn't output the default package
Also would recommend it being a function to call at a later stage. Only because its ugly! 😆 I don't mind if its not done, but it gets in front of our sweet banner
2025/01/28 10:40:52 Using encoding/json for JSON encoding
______ ______ __ ______ __
/ ____/____ / ____/_____ __ __ ____ / /_ ____ /_ __/_____ ______ ____/ /___ _____
/ / __ / __ \ / / / ___// / / // __ \ / __// __ \ / / / ___// __ // __ // _ \ / ___/
/ /_/ // /_/ // /___ / / / /_/ // /_/ // /_ / /_/ // / / / / /_/ // /_/ // __// /
\____/ \____/ \____//_/ \__, // .___/ \__/ \____//_/ /_/ \__,_/ \__,_/ \___//_/
/____//_/
GoCryptoTrader v0.1 arm64 go1.23.4 pre-release.
This version is pre-release and is not intended to be used as a production ready trading framework or bot - use at your own risk.
Copyright (c) 2014-2025 The GoCryptoTrader Developers.
GitHub: https://github.com/thrasher-corp/gocryptotrader
Kanban: https://github.com/orgs/thrasher-corp/projects/3
Slack: https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk
Issues: https://github.com/thrasher-corp/gocryptotrader/issues
2025/01/28 10:40:52 Loading config file /Users/scottg/.gocryptotrader/config.json..
exchange CoinbasePro authenticated API support disabled due to default/empty APIKey/Secret/ClientID values
Logger initialised.
- os: windows-latest | ||
goarch: amd64 | ||
psql: true | ||
skip_wrapper_tests: true | ||
sonic: false | ||
- os: ubuntu-latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last one is a docker build so it only comes up with false true, but the matrix build above, seems to be the only one with sonic set to true, but in the logs, it doesn't seem to pull the bytedance package down. I am trying to fix that now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the docker build is ded, but otherwise, looks good
PR Description
This pull request introduces a custom JSON package located in encoding/json/ to facilitate swapping between the default Go encoding/json package and the sonic library based on build tags.
Adds:
Import Updates:
All imports to the standard encoding/json package have been updated to the new custom package github.com/thrasher-corp/gocryptotrader/encoding/json.
Added basic benchmarks for both the default encoding/json and the sonic implementation to evaluate hot-swap performance.
Type of change
Please delete options that are not relevant and add an
x
in[]
as item is complete.How has this been tested
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and
also consider improving test coverage whilst working on a certain feature or package.
Checklist